﻿

using Twipler.App;
using Twipler.App.Session;

namespace Twipler.Xtensions
{
    public static class ILogExtension
    {
        public static object[] EnterMethod(this log4net.ILog logger, string methodName)
        {
            if (!App.Config.IsLoggingEnabled)
                return null;

            Current.Log.InfoFormat("Entered method {0}", methodName);
            
            DebugTimer timer = new DebugTimer();
            timer.Start();

            return new object[] { timer, methodName };
        }

        public static void InMethod(this log4net.ILog logger, string methodName)
        {
            if (App.Config.IsLoggingEnabled)
				Current.Log.InfoFormat("In      method {0}", methodName);
        }

        public static void ExitMethod(this log4net.ILog logger, object[] param)
        {
            ExitMethod(logger, param, string.Empty);
        }

        public static void ExitMethod(this log4net.ILog logger, object[] param, string additionalMessage)
        {
            if (param == null)
                return;

            DebugTimer timer = param[0] as DebugTimer;
            timer.Stop();

			Current.Log.InfoFormat("Exitted method {0} duration {1:0.00000} seconds. {2}", param[1], timer.Duration, additionalMessage);
        }
    }

}
